<?php
	require_once('db_connect.php');
	
	$user_id = $_POST['user_id'];
	$bus_numbers = $_POST['bus_numbers'];
	$facebook_id = $_POST['facebook_id'];
	$crime_rate = $_POST['crime_rate'];
	
	$query = "select * from preset where user_id='$user_id'";
	$data = mysqli_query($conn, $query)
		or die('preset 가져오는 쿼리 실패');
		
	if (mysqli_num_rows($data) > 0) {
		$query = "UPDATE preset SET  bus_numbers = '$bus_numbers', facebook_id = '$facebook_id', crime_rate = '$crime_rate' WHERE user_id = '$user_id'";
		mysqli_query($conn, $query)
			or die('preset 업데이트 쿼리 실패');
		echo json_encode(array('status' => '0'));
		exit;
	}
	else {
		$query = "insert into preset(user_id, bus_numbers, facebook_id, crime_rate) values('$user_id', '$bus_numbers', '$facebook_id', '$crime_rate')";
		mysqli_query($conn, $query)
			or die('preset 삽입 쿼리 실패');
		echo json_encode(array('status' => '0'));
		exit;
	}
?>